package com.yjhb.android.sbz.mvp.search;

import com.yjhb.android.sbz.entity.TaskInfo;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2021/1/5 14:41
 */
public class SearchPresenter extends ConventionPresenter<SearchView> {
    private final String TAG = "SearchPresenter";

    public SearchPresenter(SearchView searchView) {
        super(searchView);
    }

    @Override
    protected void onDestroy() {

    }

    public void search(String key, int size, int current) {
        if (view != null) {
            view.searchWait("正在搜索...");
        }
        HttpTool.request(model.search(key, size, current), new HttpObserver<List<TaskInfo>>() {
            @Override
            public void onResult(List<TaskInfo> data) {
                if (data == null || data.size() == 0) {
                    onError(-88, "没有找到更多信息哦~");
                    return;
                }
                if (view != null) {
                    if (current == 1)
                        view.searchSuccess(data);
                    else
                        view.searchLoadSuccess(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

}
